﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RaisingStudio.Data.Entities;

namespace WindowsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public int IssueID
        {
            get
            {
                int issueID;
                if (int.TryParse(this.textBox_IssueID.Text, out issueID))
                {
                    return issueID;
                }
                return -1;
            }
            set
            {
                this.textBox_IssueID.Text = value.ToString();
            }
        }

        public string IssueTitle
        {
            get
            {
                return this.textBox_Title.Text;
            }
            set
            {
                this.textBox_Title.Text = value;
            }
        }

        public IssueStatus IssueStatus
        {
            get
            {
                return (IssueStatus)Enum.Parse(typeof(IssueStatus), this.comboBox_IssueStatus.Text);
            }
            set
            {
                this.comboBox_IssueStatus.Text = value.ToString();
            }
        }

        public IssueType IssueType
        {
            get
            {
                return (IssueType)Enum.Parse(typeof(IssueType), this.comboBox_IssueType.Text);
            }
            set
            {
                this.comboBox_IssueType.Text = value.ToString();
            }
        }
                
        public bool IsIssueTypeNull
        {
            get
            {
                return string.IsNullOrEmpty(this.comboBox_IssueType.Text);
            }
        }

        public string IssueOwner
        {
            get
            {
                return this.textBox_Owner.Text;
            }
            set
            {
                this.textBox_Owner.Text = value;
            }
        }

        public decimal IssueProgress
        {
            get
            {
                return decimal.Parse(this.textBox_Progress.Text);
            }
            set
            {
                this.textBox_Progress.Text = value.ToString();
            }
        }

        public bool IsIssueProgressNull
        {
            get
            {
                return string.IsNullOrEmpty(this.textBox_Progress.Text);
            }
        }

        public DateTime CreateTime
        {
            get
            {
                return this.dateTimePicker1.Value;
            }
            set
            {
                this.dateTimePicker1.Value = value;
            }
        }

        public bool IsseuLocked
        {
            get
            {
                return this.checkBox_Locked.CheckState == CheckState.Checked;
            }
            set
            {
                if (value)
                {
                    this.checkBox_Locked.CheckState = CheckState.Checked;
                }
                else
                {
                    this.checkBox_Locked.CheckState = CheckState.Unchecked;
                }
            }
        }

        public bool IsIssueLockedNull
        {
            get
            {
                return this.checkBox_Locked.CheckState == CheckState.Indeterminate;
            }
        }

        public string IssueDescription
        {
            get
            {
                return this.textBox_Description.Text;
            }
            set
            {
                this.textBox_Description.Text = value;
            }
        }

        private bool _editing = false;

        public bool Editing
        {
            get { return _editing; }
            set { _editing = value; }
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            if (this.Editing)
            {
                this.textBox_IssueID.ReadOnly = true;
            }
            else
            {
                this.textBox_IssueID.Enabled = false;
                this.comboBox_IssueStatus.Enabled = false;
            }

            FillComboxIssueStatus();
            FillComboxIssueType();
        }

        private void FillComboxIssueStatus()
        {
            this.comboBox_IssueStatus.Items.Add(IssueStatus.New.ToString());
            this.comboBox_IssueStatus.Items.Add(IssueStatus.Fixed.ToString());
            this.comboBox_IssueStatus.Items.Add(IssueStatus.Close.ToString());
            this.comboBox_IssueStatus.Text = IssueStatus.New.ToString();
        }
        
        private void FillComboxIssueType()
        {
            this.comboBox_IssueType.Items.Add(string.Empty);
            this.comboBox_IssueType.Items.Add(IssueType.Issue.ToString());
            this.comboBox_IssueType.Items.Add(IssueType.Bug.ToString());
        }
    }
}
